from api.service.simliar_index_service import SimilarityMatcher


def test_match():
    # 定义关键字段

    matcher = SimilarityMatcher()

    # 添加不同类别的数据
    user1 = {"name": "Alice", "age": 30, "city": "Beijing", "user_id": 1001}
    product1 = {"name": "Phone", "price": 3999, "brand": "Apple", "timestamp": "2025-01-01"}

    matcher.add_candidate(user1, category="user")
    matcher.add_candidate(product1, category="product")

    # 查询用户
    query = {"name": "Alice", "city": "Beijing"}
    results = matcher.find_most_similar(query, category="user", top_k=1)
    print(results)
    # 输出包含匹配属性、匹配率、类别等信息

    query = {"name": "Phone", "price": 3999, "brand": "Apple", "other1": 1, "other2": 1, "other3": 1, "other4": 1,
             "other5": 1, "other6": 1, "other7": 1, "other8": 1, "other9": 1, }
    results = matcher.find_most_similar(query, category="product", top_k=1)
    print(results)
    # 查看所有类别
    print(matcher.get_categories())  # ['user', 'product']
